/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.musiclibrary.backend.services;


import cz.muni.fi.pa165.musiclibrary.api.dao.GenreDAO;
import cz.muni.fi.pa165.musiclibrary.api.dto.GenreDTO;
import cz.muni.fi.pa165.musiclibrary.api.entities.Genre;
import cz.muni.fi.pa165.musiclibrary.api.transfers.GenreT;
import cz.muni.fi.pa165.musiclibrary.api.services.GenreService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Dominik
 */
@Service
@Transactional
public class GenreServiceImpl implements GenreService{
    
    private GenreDAO genreDAO;
    
    public void setGenreDAO(GenreDAO genreDAO) {
        this.genreDAO = genreDAO;
    }
    
    public void createGenre(GenreDTO genre) {
        genreDAO.createGenre(GenreT.DTOtoGenre(genre));
    }

    public GenreDTO getGenre(Long id) {
        return GenreT.GenreToDTO(genreDAO.getGenre(id));
    }

    public List<GenreDTO> getAllGenres() {
        List<GenreDTO> allGenresDTO = new ArrayList();
        List<Genre> allGenres = genreDAO.getAllGenres();
        for(Genre genre : allGenres) {
            allGenresDTO.add(GenreT.GenreToDTO(genre));
        }
        return allGenresDTO;
    }

    public void updateGenre(GenreDTO genre) {
        genreDAO.updateGenre(GenreT.DTOtoGenre(genre));
    }

    public void deleteGenre(GenreDTO genre) {
        genreDAO.deleteGenre(GenreT.DTOtoGenre(genre));
    }    
}
